<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    const url='https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.article.pchome.net%2F00%2F45%2F32%2F38%2Fpic_lib%2Fs960x639%2FItaly_01s960x639.jpg&refer=http%3A%2F%2Fimg.article.pchome.net&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1625802644&t=88ca63e12d411f99144933f21e82e725'
    function loadImg(src){
      return new Promise((resolve,reject)=>{
        const img =document.createElement('img')
        img.onload=()=>{
          resolve(img)
        }
        img.onerror=()=>{
          const err=new Error('图片加载失败')
          reject(err)
        }
        img.src=src
      })
    }
    loadImg(url).then(img=>{
      document.body.appendChild(img)
    }).catch(err=>console.log(err))

  </script>
</body>
</html>